package com.jzo2o.customer.controller.consumer;

import com.jzo2o.common.model.PageResult;
import com.jzo2o.common.model.dto.PageQueryDTO;
import com.jzo2o.customer.model.domain.AddressBook;
import com.jzo2o.customer.model.dto.request.AddressBookUpsertReqDTO;
import com.jzo2o.customer.service.IAddressBookService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 用户地址相关接口
 *
 * @Author huang
 * @Date 2025/7/1 2025/7/1
 */
@RestController("consumerAddressController")
@RequestMapping("/consumer/address-book")
@Api(tags = "用户端 - 用户地址相关接口")
public class AddressController {
    @Autowired
    private IAddressBookService iAddressBookService;
    /**
     * 新增地址
     */
    @PostMapping
    @ApiOperation("新增地址")
    public void addaddress(@RequestBody AddressBookUpsertReqDTO dto) {
        iAddressBookService.add(dto);
    }
    /**
     * 地址铺查询
     */
    @GetMapping("/page")
    @ApiOperation("地址铺查询")
    public PageResult<AddressBook> addressPage( PageQueryDTO dto) {
        return iAddressBookService.addressPage(dto);
    }
    /**
     * 地址铺详情
     */
    @GetMapping("/{id}")
    @ApiOperation("地址铺详情")
    public AddressBook address(@PathVariable Long id) {
        return iAddressBookService.address(id);
    }
    /**
     * 地址铺修改
     */
    @PutMapping("/{id}")
    @ApiOperation("地址铺修改")
    public void updateaddress(@PathVariable Long id,@RequestBody AddressBookUpsertReqDTO dto) {
       iAddressBookService.updateaddress(id,dto);
    }
    /**
     * 地址铺删除
     */
    @DeleteMapping("/batch")
    @ApiOperation("地址铺删除")
    public void updateaddress(@RequestBody List<Long> ids) {
        iAddressBookService.delteaddress(ids);
    }


    /**
     * 设置/取消默认地址
     */
    @PutMapping("/default")
    @ApiOperation("设置/取消默认地址")
    public void defaultAddressbook(@RequestParam Integer flag,@RequestParam Long id) {
        iAddressBookService.defaultAddressbook(flag,id);
    }
    /**
     * 获取默认地址
     */
    @GetMapping("/defaultAddress")
    @ApiOperation("获取默认地址")
    public AddressBook defaultAddress() {
        return iAddressBookService.defaultAddress();
    }
}
